//
//  OALazyGetterUI.h
//  OASDK_Works
//
//  Created by ChenJie on 3/28/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#ifndef OALazyGetterUI_h
#define OALazyGetterUI_h

#import "OALazyGetterBase.h"

#define OAGetView(_name...) __oa_get_UIView__(_name)
#define OAGetLabel(_name...) __oa_get_UILabel__(_name)
#define OAGetButton(_name...) __oa_get_UIButton__(_name)
#define OAGetImageView(_name...) __oa_get_UIImageView__(_name)
#define OAGetTextField(_name...) __oa_get_UITextField__(_name)
#define OAGetTextView(_name...) __oa_get_UITextView__(_name)
#define OAGetBarButtonItem(_name...) __oa_get_UIBarButtonItem__(_name)

#define OAGetTableView(_name...) OAGetPlainTableView(_name)
#define OAGetPlainTableView(_name...) __oa_get_UIPlainTableView__(_name)
#define OAGetGroupedTableView(_name...) __oa_get_UIGroupedTableView__(_name)

/*
 * UIView
 */

#define __oa_get_UIView__(...) \
__oa_get__(UIView, ^UIView * (void){ \
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; \
    return view; \
}, __VA_ARGS__)


/*
 * UILabel
 */

#define __oa_get_UILabel__(...) \
__oa_get__(UILabel, ^UILabel * (void){ \
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; \
    NSString *labelName = NSStringFromSelector(_cmd); \
    label.textColor = [UIColor darkTextColor]; \
    label.text = labelName; \
    return label; \
}, __VA_ARGS__)


/*
 * UIButton
 */

#define __oa_get_UIButton__(...) \
__oa_get__(UIButton, ^UIButton * (void){ \
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; \
    NSString *buttonName = NSStringFromSelector(_cmd); \
    [button setTitle:buttonName forState:UIControlStateNormal]; \
    NSString *actionString = [buttonName stringByAppendingString:@"DidClick:"]; \
    SEL action = NSSelectorFromString(actionString); \
    if ([self respondsToSelector:action]) { \
        [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside]; \
    } \
    return button; \
}, __VA_ARGS__)


/*
 * UIImageView
 */

#define __oa_get_UIImageView__(...) \
__oa_get__(UIImageView, ^UIImageView * (void){ \
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; \
    imageView.contentMode = UIViewContentModeScaleAspectFit; \
    imageView.clipsToBounds = YES; \
    return imageView; \
}, __VA_ARGS__)


/*
 * UITextField
 */

#define __oa_get_UITextField__(...) \
__oa_get__(UITextField, ^UITextField * (void){ \
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectZero]; \
    NSString *textFieldName = NSStringFromSelector(_cmd); \
    textField.autocorrectionType = UITextAutocorrectionTypeNo; \
    textField.autocapitalizationType = UITextAutocapitalizationTypeNone; \
    textField.clearButtonMode = UITextFieldViewModeWhileEditing; \
    textField.placeholder = textFieldName; \
    return textField; \
}, __VA_ARGS__)


/*
 * UITextView
 */

#define __oa_get_UITextView__(...) \
__oa_get__(UITextView, ^UITextView * (void){ \
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectZero]; \
    textView.autocorrectionType = UITextAutocorrectionTypeNo; \
    textView.autocapitalizationType = UITextAutocapitalizationTypeNone; \
    return textView; \
}, __VA_ARGS__)


/*
 * UIBarButtonItem
 */

#define __oa_get_UIBarButtonItem__(...) \
__oa_get__(UIBarButtonItem, ^UIBarButtonItem * (void){ \
    NSString *itemName = NSStringFromSelector(_cmd); \
    NSString *actionName = [itemName stringByAppendingString:@"DidClick:"]; \
    SEL action = NSSelectorFromString(actionName); \
    if (![self respondsToSelector:action]) { \
        action = nil; \
    } \
    UIBarButtonItem *barButtonItem \
    = [[UIBarButtonItem alloc] initWithTitle:itemName \
                                       style:UIBarButtonItemStylePlain \
                                      target:self \
                                      action:action]; \
    return barButtonItem; \
}, __VA_ARGS__)


/*
 * UITableView
 */

#define __oa_get_UIPlainTableView__(...) \
__oa_get__(UITableView, ^UITableView * (void){ \
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; \
    __oa_get_tableView_snippet \
}, __VA_ARGS__)

#define __oa_get_UIGroupedTableView__(...) \
__oa_get__(UITableView, ^UITableView * (void){ \
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped]; \
    __oa_get_tableView_snippet \
}, __VA_ARGS__)


#define __oa_get_tableView_snippet \
tableView.separatorStyle = UITableViewCellSeparatorStyleNone; \
tableView.estimatedRowHeight = 0; \
tableView.estimatedSectionHeaderHeight = 0; \
tableView.estimatedSectionFooterHeight = 0; \
return tableView; \



//tableView.backgroundColor = OAColor(efefef); \

#endif /* OALazyGetterUI_h */
